﻿#include "singlepartsettings.h"
#include "ui_singlepartsettings.h"
#include <QApplication>



//-----------------------------------------------------------------------------
SinglePartSettings::SinglePartSettings(ImagePart *part,
									   double scale,
									   int contrast,
									   bool optionCleanImage,
									   Widget *parent) :
	QDialog(parent),
	ui(new Ui::SinglePartSettings)
{
	ui->setupUi(this);

	QStyle* style = qApp->style ();

	ui->size->setText (tr ("Dimensions : %1 x %2").arg (part->rectangle ().width ()).arg (part->rectangle ().height ()));

	ui->ok->setIcon (style->standardIcon (QStyle::SP_DialogOkButton));
	ui->cancel->setIcon (style->standardIcon (QStyle::SP_DialogCancelButton));
	ui->deflt->setIcon (style->standardIcon (QStyle::SP_ArrowUp));

	m_part = part;
	m_scale = scale;
	m_contrast = contrast;
	m_optionCleanImage = optionCleanImage;

	ui->scale->setRange (0.1, 3.0);
	ui->scale->setAccelerated (true);
	ui->scale->setSingleStep (0.1);
	ui->scale->setDecimals (1);
	ui->contrast->setRange (1, 99);
	ui->contrast->setAccelerated (true);

	ui->scale->setValue (part->scale1 ());
	ui->contrast->setValue (part->guiContrast ());
	ui->optionCleanImage->setChecked (part->optionCleanImage ());

	setWindowTitle (tr ("Réglages spécifiques"));
}
//----------------------------------------
SinglePartSettings::~SinglePartSettings()
{
	delete ui;
}
//----------------------------------------------
void SinglePartSettings::changeEvent(QEvent *e)
{
	QDialog::changeEvent(e);
	switch (e->type()) {
	case QEvent::LanguageChange:
		ui->retranslateUi(this);
		break;
	default:
		break;
	}
}
//-----------------------------------------------
void SinglePartSettings::on_ok_clicked()
{
	m_part->setScale1 (ui->scale->value ());
	m_part->setContrastFromGUI (ui->contrast->value ());
	m_part->setOptionCleanImage (ui->optionCleanImage->isChecked ());
	accept ();
}
//-------------------------------------------
void SinglePartSettings::on_cancel_clicked()
{
	reject ();
}
//------------------------------------------
void SinglePartSettings::on_deflt_clicked()
{
	ui->scale->setValue (m_scale);
	ui->contrast->setValue (100 * m_contrast / 255);
	ui->optionCleanImage->setChecked (m_optionCleanImage);

}
